home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 6 / CU Amiga Magazine's Super CD-ROM 06 (1996)(EMAP Images)(GB)(Track 1 of 4)[!][issue 1997-01].iso / cucd / prog / dopussdk / source / modinit.c
C/C++ Source or Header  |  1996-08-27  |  4KB  |  146 lines

  1. /****************************************************************************
  2.  
  3.  modinit.c - standard initialisation for Opus 5 modules
  4.  
  5.  ****************************************************************************/
  6.  
  7. #define _DOPUS_MODULE_DEF
  8. #include <dopus/modules.h>
  9.  
  10. #ifndef CLIB_EXEC_PROTOS_H
  11. #include <clib/exec_protos.h>
  12. #include <pragmas/exec_pragmas.h>
  13. #endif
  14.  
  15. #ifndef EXEC_MEMORY_H
  16. #include <exec/memory.h>
  17. #endif
  18.  
  19. #ifndef CLIB_LOCALE_PROTOS_H
  20. #include <clib/locale_protos.h>
  21. #include <pragmas/locale_pragmas.h>
  22. #endif
  23.  
  24. // SAS/C stuff
  25. int __saveds __UserLibInit(void);
  26. void __saveds __UserLibCleanup(void);
  27.  
  28. // The libraries we open
  29. struct Library *DOSBase;
  30. struct Library *DOpusBase;
  31. struct Library *IntuitionBase;
  32. struct Library *GfxBase;
  33. struct Library *IconBase;
  34. struct Library *LocaleBase;
  35. struct Library *UtilityBase;
  36. struct Library *LayersBase;
  37. struct Library *WorkbenchBase;
  38. struct Library *GadToolsBase;
  39. struct Library *AslBase;
  40. struct Library *DiskfontBase;
  41. struct Library *TimerBase;
  42. struct Library *RexxSysBase;
  43.  
  44. // Locale pointer
  45. struct DOpusLocale *locale;
  46.  
  47. // Library initialisation code
  48. __saveds __UserLibInit()
  49. {
  50.     // Initialise pointers
  51.     DOpusBase=0;
  52.     IntuitionBase=0;
  53.     GfxBase=0;
  54.     IconBase=0;
  55.     LocaleBase=0;
  56.     UtilityBase=0;
  57.     LayersBase=0;
  58.     WorkbenchBase=0;
  59.     GadToolsBase=0;
  60.     DiskfontBase=0;
  61.     AslBase=0;
  62.     RexxSysBase=0;
  63.     locale=0;
  64.  
  65.     // Get DOS library (can't really fail)
  66.     DOSBase=OpenLibrary("dos.library",0);
  67.  
  68.     // Open other libraries we need
  69.     if (!(DOpusBase=OpenLibrary("dopus5.library",55)) ||
  70.         !(IntuitionBase=OpenLibrary("intuition.library",37)) ||
  71.         !(GfxBase=OpenLibrary("graphics.library",37)) ||
  72.         !(IconBase=OpenLibrary("icon.library",37)) ||
  73.         !(LayersBase=OpenLibrary("layers.library",37)) ||
  74.         !(GadToolsBase=OpenLibrary("gadtools.library",37)) ||
  75.         !(AslBase=OpenLibrary("asl.library",37)) ||
  76.         !(DiskfontBase=OpenLibrary("diskfont.library",37)) ||
  77.         !(TimerBase=GetTimerBase()) ||
  78.         !(UtilityBase=OpenLibrary("utility.library",37))) return 1;
  79.  
  80.     // Libraries we don't need but want
  81.     WorkbenchBase=OpenLibrary("workbench.library",0);
  82.     RexxSysBase=OpenLibrary("rexxsyslib.library",0);
  83.  
  84.     // Allocate and open locale data
  85.     if (!(locale=AllocVec(sizeof(struct DOpusLocale),MEMF_CLEAR)))
  86.         return 1;
  87.     init_locale_data(locale);
  88.  
  89.     // Open locale library
  90.     if (LocaleBase=OpenLibrary("locale.library",38))
  91.     {
  92.         // Initialise catalog
  93.         locale->li_LocaleBase=LocaleBase;
  94.         if (module_info.locale_name)
  95.             locale->li_Catalog=OpenCatalogA(NULL,module_info.locale_name,0);
  96.         locale->li_Locale=OpenLocale(0);
  97.     }
  98.  
  99.     // Succeeded
  100.     return 0;
  101. }
  102.  
  103.  
  104. // Clean up
  105. void __saveds __UserLibCleanup()
  106. {
  107.     // Free locale stuff
  108.     if (locale)
  109.     {
  110.         if (LocaleBase)
  111.         {
  112.             CloseLocale(locale->li_Locale);
  113.             CloseCatalog(locale->li_Catalog);
  114.             CloseLibrary(LocaleBase);
  115.         }
  116.         FreeVec(locale);
  117.     }
  118.  
  119.     // Close libraries
  120.     CloseLibrary(DOpusBase);
  121.     CloseLibrary(IntuitionBase);
  122.     CloseLibrary(GfxBase);
  123.     CloseLibrary(IconBase);
  124.     CloseLibrary(LayersBase);
  125.     CloseLibrary(UtilityBase);
  126.     CloseLibrary(WorkbenchBase);
  127.     CloseLibrary(DiskfontBase);
  128.     CloseLibrary(RexxSysBase);
  129.     CloseLibrary(AslBase);
  130.     CloseLibrary(DOSBase);
  131. }
  132.  
  133.  
  134. // This routine is called by Opus to find out what the module does
  135. ModuleInfo *__asm __saveds L_Module_Identify(register __d0 int num)
  136. {
  137.     // Return module information
  138.     if (num==-1) return &module_info;
  139.  
  140.     // Valid function number?
  141.     if (num>module_info.function_count || !(module_info.function[num].desc)) return 0;
  142.  
  143.     // Return function description
  144.     return (ModuleInfo *)DOpusGetString(locale,module_info.function[num].desc);
  145. }
  146.